package com.njworkorder.Service.Impl;

import com.github.yulichang.base.MPJBaseServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.njworkorder.Entity.Plan;
import com.njworkorder.Entity.PlanMetering;
import com.njworkorder.Service.PlanService;
import com.njworkorder.Mapper.PlanMapper;
import com.njworkorder.VO.PMSummaryTable;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.CompletableFuture;

/**
* @author iron
* @description 针对表【plan】的数据库操作Service实现
* @createDate 2025-01-16 14:52:02
*/
@Service
public class PlanServiceImpl extends MPJBaseServiceImpl<PlanMapper, Plan>
    implements PlanService{

    @Async
    @Override
    public CompletableFuture<List<PlanMetering>> getPlanMetering(int year) {

        MPJLambdaWrapper<Plan> wrapper = new MPJLambdaWrapper<Plan>()
                .select(PlanMetering::getMeteringInventoryId)
                .selectAs("sum(t1.unit_price * t1.amount)",PlanMetering::getUnitPrice)

                .leftJoin(PlanMetering.class,PlanMetering::getPlanId,Plan::getId)
                .apply("YEAR(t.publish_time) = " + year);
        return CompletableFuture.completedFuture(selectJoinList(PlanMetering.class, wrapper));
    }

    @Override
    public List<PMSummaryTable> getPMSummaryTable() {
        return baseMapper.getPMSummaryTable();
    }
}




